//
//  EnduranceCell.m
//  TT
//
//  Created by Lenny on 16/4/21.
//  Copyright © 2016年 Lenny. All rights reserved.
//

#import "EnduranceCell.h"

@interface EnduranceCell ()

//第一层
@property(nonatomic,strong)UIButton *leftB;
@property(nonatomic,strong)UIView *midV;
@property(nonatomic,strong)UIButton *rightB;

//具体视图
@property(nonatomic,strong)UILabel *nameL;
@property(nonatomic,strong)UILabel *addrL;
@property(nonatomic,strong)UILabel *proDesL;
@property(nonatomic,strong)UIImageView *proIV;
@property(nonatomic,strong)UILabel *proL;
@property(nonatomic,strong)UILabel *describeL;
@property(nonatomic,strong)UILabel *timeL;
@property(nonatomic,strong)UILabel *distanceL;
@property(nonatomic,strong)UIImageView *selectIV;

@property(nonatomic,strong)void(^block)(UIButton *sender);


@end

@implementation EnduranceCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self addUI];
    }
    return self;
}

#pragma mark - public motheds

- (void)addUI {
    
    [self addSubview:self.leftB];
    [self addSubview:self.midV];
    [self addSubview:self.rightB];
    
    UIView *lineV = [[UIView alloc] init];
    lineV.backgroundColor = WL_M_Line_Color;
   
    UILabel *toL = [[UILabel alloc] init];
    toL.text = @"到这去";
    toL.font = [UIFont systemFontOfSize:10];
    
    UIImageView *imageV = [[UIImageView alloc] init];
    imageV.image = [UIImage imageNamed:@"icon_time"];
    
    [self addSubview:lineV];
    [self.rightB addSubview:toL];
    [self.rightB addSubview:imageV];
    
    [self.midV addSubview:self.proIV];
    [self.midV addSubview:self.nameL];
    [self.midV addSubview:self.addrL];
    [self.midV addSubview:self.proDesL];
    
    [self.leftB addSubview:self.distanceL];
    [self.leftB addSubview:self.describeL];
    [self.leftB addSubview:self.timeL];
    [self.leftB addSubview:self.selectIV];
    
    __weak typeof(self) weakSelf = self;
    [self.leftB mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.equalTo(weakSelf.mas_height);
    }];
    
    [self.rightB mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.equalTo(weakSelf.mas_height);
    }];
    
    [self.midV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(weakSelf.leftB.mas_right);
        make.right.equalTo(weakSelf.rightB.mas_left);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(weakSelf.rightB.mas_left);
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(1);
    }];
    
    [toL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(weakSelf.rightB.mas_centerY);
        make.centerX.equalTo(weakSelf.rightB.mas_centerX).offset(-15);
    }];
    
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(toL.mas_centerY);
        make.left.equalTo(toL.mas_right).offset(5);
    }];
    
    [self.proIV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
    }];
    
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(weakSelf.midV.mas_centerY).offset(-10);
        make.left.mas_equalTo(20);
    }];
    
    [self.addrL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(weakSelf.nameL.mas_bottom);
        make.left.equalTo(weakSelf.nameL.mas_left);
    }];
    
    [self.proDesL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.mas_equalTo(-3);
        make.left.equalTo(weakSelf.nameL.mas_left);
    }];
    
    [self.timeL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(weakSelf.leftB);
    }];
    
    [self.describeL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(weakSelf.timeL.mas_top).offset(-5);
        make.centerX.equalTo(weakSelf.leftB.mas_centerX);
    }];
    
    [self.distanceL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(weakSelf.timeL.mas_bottom).offset(5);
        make.centerX.equalTo(weakSelf.leftB.mas_centerX);
    }];
    
    [self.selectIV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
}


- (void)addEvent:(void (^)(UIButton *))eventBlock {
    
    self.block = eventBlock;
}

#pragma mark - event private

- (void)btnAction:(UIButton *)sender {
    
    if (self.block != nil) {
        self.block(sender);
    }
}

#pragma mark - setters and getters

- (UIButton *)leftB {
    
    if (_leftB == nil) {
        
        _leftB = [[UIButton alloc] init];
        _leftB.tag = 1;
        [_leftB setBackgroundImage:[UIColor colorToImage:WL_M_View_Gray_Color] forState:UIControlStateNormal];
        [_leftB setBackgroundImage:[UIColor colorToImage:WL_Top_Color] forState:UIControlStateSelected];
        [_leftB addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftB;
}

- (UIView *)midV {
    
    if (_midV == nil) {
        
        _midV = [[UIView alloc] init];
        _midV.backgroundColor = [UIColor whiteColor];
    }
    return _midV;
}

- (UIButton *)rightB {
    
    if (_rightB == nil) {
        
        _rightB = [[UIButton alloc] init];
        _rightB.backgroundColor = [UIColor whiteColor];
        _rightB.tag = 2;
        [_rightB addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightB;
}

- (UILabel *)nameL {
    
    if (_nameL == nil) {
        
        _nameL = [[UILabel alloc] init];
        _nameL.text = @"中石油司法纠纷开始减肥";
        _nameL.textColor = WL_Name_Color;
        _nameL.font = [UIFont systemFontOfSize:15];
    }
    return _nameL;
}

- (UILabel *)addrL {
    
    if (_addrL == nil) {
        
        _addrL = [[UILabel alloc] init];
        _addrL.text = @"wangsjgakl双方尽快释放";
        _addrL.textColor = WL_Desc_Color;
        _addrL.font = [UIFont systemFontOfSize:13];
    }
    return _addrL;
}

- (UIImageView *)proIV {
    
    if (_proIV == nil) {
        
        _proIV = [[UIImageView alloc] init];
        _proIV.image = [UIImage imageNamed:@"icon_promotion_g"];
    }
    return _proIV;
}

- (UILabel *)describeL {
    
    if (_describeL == nil) {
        
        _describeL = [[UILabel alloc] init];
        _describeL.text = @"最快";
        _describeL.font = [UIFont systemFontOfSize:19];
    }
    return _describeL;
}

- (UILabel *)timeL {
    
    if (_timeL == nil) {
        
        _timeL = [[UILabel alloc] init];
        _timeL.text = @"12分钟";
        _timeL.font = [UIFont systemFontOfSize:12];
    }
    return _timeL;
}

- (UILabel *)distanceL {
    
    if (_distanceL == nil) {
        
        _distanceL = [[UILabel alloc] init];
        _distanceL.text = @"4.9公里";
        _distanceL.font = [UIFont systemFontOfSize:10];
    }
    return _distanceL;
}

- (UIImageView *)selectIV {
    
    if (_selectIV == nil) {
        
        _selectIV = [[UIImageView alloc] init];
        _selectIV.image = [UIImage imageNamed:@"icon_time"];
    }
    return _selectIV;
}

- (UILabel *)proDesL {
    
    if (_proDesL == nil) {
        
        _proDesL = [[UILabel alloc] init];
        _proDesL.textColor = WL_Top_Color;
        _proDesL.font = [UIFont systemFontOfSize:12];
        _proDesL.text = @"waanglag";
    }
    return _proDesL;
}

@end
